package com.lovo.hb.dao;

import com.lovo.hb.dto.RoleDto;
import com.lovo.hb.entity.RoleEntity;
import com.lovo.hb.entity.UserRoleEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;
import java.util.Map;

public interface IUserRoleDao extends CrudRepository<UserRoleEntity,Long> {

    @Query("from UserRoleEntity where user.userId=?1 and tag=0")
    public List<UserRoleEntity> findAllByUserId(long id);

    @Query("select new map(user.userName,role.roleName) from UserRoleEntity where user.userId=?1 and tag=0")
    public List<Map> findAllByUserIdMap(long id);

    @Query("select new com.lovo.hb.dto.RoleDto(user.userName,role.roleName) from UserRoleEntity" +
            " where user.userName=?1 and tag=?2")
    public List<RoleDto> findAllByUserName(String userName,int tag);


}
